Skip to content

Conversation

johahor
Copy link
Member

@johahor johahor commented Nov 3, 2026

Closes #33

Summary

After switching from Open Library to our GraphQL API, the page tests were removed and 11 of the remaining 25 component tests failed. This PR makes pnpm test pass again and adds page tests using Apollo's MockedProvider, so no real requests are sent to the backend.

Changes

Outdated component tests fixed

  • SearchBar, BookFilters: use the genres search param (renamed from genre).
  • BookPagination: rewritten for link-based pagination. Also checks that the search and filters are kept when changing page.
  • BookCard: rendered with MockedProvider, snapshot regenerated.
  • FavoriteButton: rewritten for favorites stored in the backend. A logged out user gets the login dialog, a logged in user can add and remove favorites, and an error message is shown when saving fails.

New page tests

  • home.test.tsx: shows results from the API, sends search/filters/sort/page as variables to the API (so filtering and sorting happen on the whole result set), empty result, API error, and opening a book and going back to the same search.
  • selectedBook.test.tsx: shows book details, "Book Not Found", and browsing to the next book.

Helpers in app/test/: renderRoutes (router + MockedProvider), mocks (GraphQL responses) and session (logged in/out session for the mocked auth client).

useSearchBooks and useBook now export their queries so tests can mock them. No other app code is changed.

How to test

cd frontend
pnpm test

35/35 tests pass. Lint and Prettier are clean.

Notes

  • The warning Unknown query named "FavoriteBooks" requested in refetchQueries in the favorite tests is expected. Apollo only refetches queries that are mounted, and the favorites list (profile page) isn't mounted in the test. It's a dev-only warning.
  • The "Go back" link on the book page is exposed as role="button" by the Button component, so the test looks it up as a button. It should probably be a plain link; that's for a separate PR.
  • E2E tests and API tests are not part of this issue.

AI usage

The tests and this description were generated with AI (Claude) and reviewed by the PR author before opening the PR.

Fix outdated component tests (genres param, link-based pagination, favorites stored in the backend) and add page tests for the home and book pages. Closes #33.
@johahor johahor requested a review from a team as a code owner November 3, 2026 13:14
Copy link
Member

@martakam martakam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to get these updated. The tests work as expected for me too

@johahor johahor merged commit 97b4a3f into main Nov 3, 2026
@johahor johahor mentioned this pull request Nov 6, 2026
@martakam martakam added the test Writing/editing tests label Nov 7, 2026
@martakam martakam added this to the Deliverable 4 milestone Nov 7, 2026
@martakam martakam deleted the test/apollo-mocked-provider branch November 8, 2026 13:36
Sign in to join this conversation on GitHub.
Labels
test Writing/editing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: rewrite page tests with Apollo MockedProvider
2 participants